/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NestedWebLogoInputer.java
 *
 * Created on Nov 15, 2011, 1:42:19 PM
 */
package edu.ufl.cise.bioinformatics.nestedweblogo;

import java.util.HashMap;
import java.util.Map;

import javax.swing.table.DefaultTableModel;

/**
 * 
 * @author sagarg
 */
public class NestedWebLogoInputer extends javax.swing.JFrame {

	private int patternTableRowNumber = 0;
	
	SequenceLogoDrawer drawer = null;

	/** Creates new form NestedWebLogoInputer */
	public NestedWebLogoInputer(SequenceLogoDrawer drawer) {	
		this.drawer = drawer;
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jPanel1 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		sourcePositionSetStartPositionTextBox = new javax.swing.JTextField();
		sourcePositionSetEndPositionTextBox = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		patternTextBox = new javax.swing.JTextField();
		jScrollPane1 = new javax.swing.JScrollPane();
		patternTable = new javax.swing.JTable();
		addGroupButton = new javax.swing.JButton();
		submitButton = new javax.swing.JButton();
		jPanel2 = new javax.swing.JPanel();
		jLabel2 = new javax.swing.JLabel();
		targetPositionSetStartPositionTextBox = new javax.swing.JTextField();
		targetPositionSetEndPositionTextBox = new javax.swing.JTextField();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setResizable(false);

		jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(
				javax.swing.border.BevelBorder.RAISED));

		jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel1.setText("Position Set 1");
		jLabel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout
				.setHorizontalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addGap(65, 65, 65)
										.addComponent(
												jLabel1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												96,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(67, 67, 67))
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								jPanel1Layout
										.createSequentialGroup()
										.addGap(36, 36, 36)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(
																sourcePositionSetEndPositionTextBox,
																javax.swing.GroupLayout.Alignment.LEADING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																153,
																Short.MAX_VALUE)
														.addComponent(
																sourcePositionSetStartPositionTextBox,
																javax.swing.GroupLayout.Alignment.LEADING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																153,
																Short.MAX_VALUE))
										.addGap(39, 39, 39)));
		jPanel1Layout
				.setVerticalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												jLabel1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												26,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(13, 13, 13)
										.addComponent(
												sourcePositionSetStartPositionTextBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(
												sourcePositionSetEndPositionTextBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(41, Short.MAX_VALUE)));

		jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel3.setText("Pattern");
		jLabel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

		patternTable.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] {

				}, new String[] { "Pattern", "Source start Position",
						"Source end Position", "Target start Position",
						"Target End Position" }) {
			Class[] types = new Class[] { java.lang.String.class,
					java.lang.String.class, java.lang.String.class,
					java.lang.String.class, java.lang.String.class };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}
		});
		jScrollPane1.setViewportView(patternTable);

		addGroupButton.setText("Add Group");
		addGroupButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				addGroupButtonActionPerformed(evt);
			}
		});

		submitButton.setText("Submit");
		submitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				submitButtonActionPerformed(evt);
			}
		});

		jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(
				javax.swing.border.BevelBorder.RAISED));

		jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel2.setText("Position Set 2");
		jLabel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout
				.setHorizontalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addGap(65, 65, 65)
										.addComponent(
												jLabel2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												96,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(67, 67, 67))
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								jPanel2Layout
										.createSequentialGroup()
										.addGap(36, 36, 36)
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(
																targetPositionSetEndPositionTextBox,
																javax.swing.GroupLayout.Alignment.LEADING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																153,
																Short.MAX_VALUE)
														.addComponent(
																targetPositionSetStartPositionTextBox,
																javax.swing.GroupLayout.Alignment.LEADING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																153,
																Short.MAX_VALUE))
										.addGap(39, 39, 39)));
		jPanel2Layout
				.setVerticalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												jLabel2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												26,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(13, 13, 13)
										.addComponent(
												targetPositionSetStartPositionTextBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(
												targetPositionSetEndPositionTextBox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(41, Short.MAX_VALUE)));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jScrollPane1,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						514,
																						Short.MAX_VALUE)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addComponent(
																										addGroupButton)
																								.addGap(55,
																										55,
																										55)
																								.addComponent(
																										submitButton,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										85,
																										javax.swing.GroupLayout.PREFERRED_SIZE)))
																.addContainerGap())
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addComponent(
																						patternTextBox,
																						javax.swing.GroupLayout.Alignment.LEADING,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						234,
																						Short.MAX_VALUE)
																				.addComponent(
																						jPanel1,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE))
																.addGap(26, 26,
																		26)
																.addComponent(
																		jPanel2,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addGap(30, 30,
																		30))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel3,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		75,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addContainerGap(
																		449,
																		Short.MAX_VALUE)))));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jPanel1,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addGap(18, 18,
																		18)
																.addComponent(
																		jLabel3,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		26,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addGap(18, 18,
																		18)
																.addComponent(
																		patternTextBox,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		14,
																		Short.MAX_VALUE)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																				.addComponent(
																						addGroupButton)
																				.addComponent(
																						submitButton)))
												.addComponent(
														jPanel2,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(18, 18, 18)
								.addComponent(jScrollPane1,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										223,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap()));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void addGroupButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addGroupButtonActionPerformed
		String sourcePositionSetEndPosition = sourcePositionSetEndPositionTextBox
				.getText();
		String sourcePositionSetStartPosition = sourcePositionSetStartPositionTextBox
				.getText();
		String targetPositionSetEndPosition = targetPositionSetEndPositionTextBox
				.getText();
		String targetPositionSetStartPosition = targetPositionSetStartPositionTextBox
				.getText();
		String pattern = patternTextBox.getText();

		System.out.println("Position Set 1: " + sourcePositionSetStartPosition
				+ " - " + sourcePositionSetEndPosition);
		System.out.println("Position Set 2: " + targetPositionSetStartPosition
				+ " - " + targetPositionSetEndPosition);
		System.out.println("Pattern: " + pattern);

		// patternTable.getModel().setValueAt(pattern ,
		// patternTableRowNumber,0);
		// patternTable.getModel().setValueAt(sourcePositionSetStartPosition ,
		// patternTableRowNumber,1);
		// patternTable.getModel().setValueAt(sourcePositionSetEndPosition ,
		// patternTableRowNumber,2);
		// patternTable.getModel().setValueAt(targetPositionSetStartPosition ,
		// patternTableRowNumber,3);
		// patternTable.getModel().setValueAt(targetPositionSetEndPosition ,
		// patternTableRowNumber,4);

		String[] data = new String[5];
		data[0] = pattern;
		data[1] = sourcePositionSetStartPosition;
		data[2] = sourcePositionSetEndPosition;
		data[3] = targetPositionSetStartPosition;
		data[4] = targetPositionSetEndPosition;

		((DefaultTableModel) patternTable.getModel()).insertRow(
				patternTableRowNumber, data);
		patternTableRowNumber++;
	}// GEN-LAST:event_addGroupButtonActionPerformed

	private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_submitButtonActionPerformed
		int rowCount = patternTable.getModel().getRowCount();
		
		Map<String,NestedWebLogoDataStructure> nestedWeblogoMap = new HashMap<String, NestedWebLogoDataStructure>();
		
//		drawer.clearNestedWebLogoMap();
		
		if(rowCount > 0){
			for(int i=0 ; i<rowCount ; i++){
				
				patternTable.getModel().getValueAt(i, 0);
				
			/*	NestedWebLogoDataStructure nestedWebLogo = new NestedWebLogoDataStructure();
				nestedWebLogo.setWildCardPattern((String)patternTable.getModel().getValueAt(i, 0));
				nestedWebLogo.setSourceWebLogoStartPosition(Integer.parseInt((String)patternTable.getModel().getValueAt(i, 1)));
				nestedWebLogo.setSourceWebLogoEndPosition(Integer.parseInt((String)patternTable.getModel().getValueAt(i, 2)));
				nestedWebLogo.setTargetWebLogoStartPosition(Integer.parseInt((String)patternTable.getModel().getValueAt(i, 3)));
				nestedWebLogo.setTargetWebLogoEndPosition(Integer.parseInt((String)patternTable.getModel().getValueAt(i, 4)));
				
				String key = nestedWebLogo.getWildCardPattern()+":"+nestedWebLogo.getSourceWebLogoStartPosition()+":"
				+nestedWebLogo.getSourceWebLogoEndPosition()+":"+nestedWebLogo.getTargetWebLogoStartPosition()+":"
				+nestedWebLogo.getTargetWebLogoEndPosition();
				
				nestedWeblogoMap.put(key, nestedWebLogo);*/
				
//				drawer.addEntryToNestedWebLogoMap(nestedWebLogo);
			}						
		}
		
//		drawer.buildWebLogo(nestedWeblogoMap);
		this.dispose();
		repaint();
		drawer.repaint();
	}// GEN-LAST:event_submitButtonActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed"
		// desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase
		 * /tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(
					NestedWebLogoInputer.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(
					NestedWebLogoInputer.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(
					NestedWebLogoInputer.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(
					NestedWebLogoInputer.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new NestedWebLogoInputer(new SequenceLogoDrawer()).setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton addGroupButton;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable patternTable;
	private javax.swing.JTextField patternTextBox;
	private javax.swing.JTextField sourcePositionSetEndPositionTextBox;
	private javax.swing.JTextField sourcePositionSetStartPositionTextBox;
	private javax.swing.JButton submitButton;
	private javax.swing.JTextField targetPositionSetEndPositionTextBox;
	private javax.swing.JTextField targetPositionSetStartPositionTextBox;
	// End of variables declaration//GEN-END:variables
}
